package tw.edu.tku.im.maze;
import org.json.JSONException;
import org.json.JSONObject;


public class UpdateGameReqParser extends PacketParser {
   public static UpdateGameReqParser INSTANCE = new UpdateGameReqParser();
   
   private UpdateGameReqParser() { }
   
   @Override
   public UpdateGameReq parse(JSONObject jsonObj) throws JSONException {
      JSONObject parameter = jsonObj.getJSONObject("parameter");
      int roomID = parameter.getInt("roomID");
      String userID = parameter.getString("userID");
      int ticket = parameter.getInt("ticket");
      if(parameter.isNull("lastTimestamp")) {
         return new UpdateGameReq(roomID, userID, ticket);
      }
      else {
         String lastTimestamp = parameter.getString("lastTimestamp");
         return new UpdateGameReq(roomID, userID, ticket, lastTimestamp);
      }
   }

   @Override
   public String acceptName() {
      return "updateGame";
   }
   
}
